<?php
// created by: alfin akhret
// related files :
// model/mdue_date.php
// view/f-due-date.php
// view/grid-due-date.php
// library/serversidedatatables.php
class Mconsignment_list extends CI_Model
{
	public function __construct()
	{
		parent::__construct();
		$this->load->library('serversidedatatables');
	}

	//cari data jatuh tempo
	function get_consignment_list($cluster_id = '')
	{
		$user_id = "";
		if($this->session->userdata('user_id') != "")
		{
			$user_id = $this->session->userdata('user_id');
		}
		else {
			$user_id = $this->session->userdata('username');
		}



		//operasi pengambilan data jatuh tempo sell in
		$sIndexColumn = "no_consignment"; 
        $status="";
        $defaultOrder = "0";
        $orderingSequence = "desc";

        $aColumns = array("no_consignment", "sales", "tgl_consignment", "partner");

        $str1 = array(" , ", ", ' '");
        $str2 = array(" ", " ");
        // $inputQuery = "select ".str_replace($str1, $str2, implode(", ", $aColumns))." from v_ssp_consignment_list 
        // 				where f_get_cluster(created_by) = f_get_cluster('".$user_id."')";

        $inputQuery = "select ".str_replace($str1, $str2, implode(", ", $aColumns))." from v_ssp_consignment_list 
                where cluster_id = $cluster_id";

        return $this->serversidedatatables->executeServerSideProcess($defaultOrder, $status, $user_id, $inputQuery, $aColumns, $sIndexColumn, $orderingSequence);
           
		
	}

	//close kasus jatuh tempo
	function close($sell_in_id)
	{
		$this->db->where('sell_in_id', $sell_in_id);
		$this->db->update('t_trx_sell_in', array("istatus" => '3')); 
	}

}